//获取用户信息
exports.getUser = async function (context) {
    try {
        const cloud = context.cloud;
        let data = context.data;
        const result = await cloud.db.collection('members').find(data, {
            sort: { _id: -1 },
        })
        
        return {
            status: 'success',
            data: result,
        };
    }catch(e){
        return {
            status: 'fail',
            data: e
        };
    }
}

//添加或修改单条数据
exports.addUser = async (context) => {
    const cloud = context.cloud;
    const data = context.data;
    if (!!data.id) {
        const result = await cloud.db.collection('members').replaceOne(
            {
                _id: data.id
            },
            data
        );
        return result;
    } else {
        const result = cloud.db.collection('members').insertOne(data)
        return result;
    }
};
//删除单条数据
exports.deleteItemById = async function (context) {
    const cloud = context.cloud;
    const data = context.data;
    cloud.db.collection('members').deleteMany({ _id: data.id }).then((res) => {
        return res;
    })
}